<?php
session_start();
include_once("conn.php"); 

function get_attitude($joke_id) { 

$attitude1= mysql_num_rows(mysql_query("select * from view_history where attitude='1' and joke_id='".$joke_id."'"));
$attitude2= mysql_num_rows(mysql_query("select * from view_history where attitude='2' and joke_id='".$joke_id."'"));
$attitude3= mysql_num_rows(mysql_query("select * from view_history where attitude='3' and joke_id='".$joke_id."'"));

$result = mysql_query("select * from joke where id='".$joke_id."'");
$row = mysql_fetch_array($result);

if(isset($_SESSION["user_name"])==false || $row["author"]==$_SESSION["user_name"])
{
	return $attitude1."|".$attitude2."|".$attitude3."|"."-1"; 
}

$res=mysql_query("select * from view_history where joke_id='".$joke_id."' and user_name='".$_SESSION["user_name"]."'");
if($res_row=mysql_fetch_array($res))
{
	$selected=$res_row["attitude"];
}
else
{
	$selected='0';
}

return $attitude1."|".$attitude2."|".$attitude3."|".$selected; 
} 

?>